//
//  CTAboutUsView.m
//  ConstellationTalk_0.1
//
//  Created by riley on 15/4/28.
//  Copyright (c) 2015年 riley chu. All rights reserved.
//

#import "CTAboutUsView.h"
#import "CTDebugManager.h"
#import "CTHeader.h"
#import "CTAppLanguage.h"
#import "UIViewAdditions.h"
#import "CTSetView_Def.h"

#define CT_SETVIEW_BUTTON0 1000
#define CT_SETVIEW_BUTTON1 1001
#define CT_SETVIEW_BUTTON2 1002
//#define CT_SETVIEW_BUTTON3 1003

@interface CTAboutUsView()
{
    UIView *topView;
    UILabel *versionLabel;
}


@end

@implementation CTAboutUsView
@synthesize delegate;


- (void)dealloc
{
    [topView removeFromSuperview];
    topView = nil;
    [versionLabel removeFromSuperview];
    versionLabel = nil;
    
    delegate = nil;
    
    [CTDebugManager showDebugLogInfo:@"dealloc : CTAboutUsView Is Removed!!!"];
}

- (instancetype)init
{
    self = [super init];
    if (self)
    {
        self.backgroundColor = [UIColor clearColor];
        self.frame = CGRectMake(0, 0,CT_HEADER_SCREEN_WIDTH,CT_HEADER_SCREEN_HEIGHT);
        self.backgroundColor = CT_HEADER_WHITE_COLOR;
                [self createTitleView];
                [self createAboutUsView];
    }
    return self;
}
- (void) createTitleView
{
    topView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, CT_HEADER_SCREEN_WIDTH, 64)];
//    topView.backgroundColor = CT_HEADER_ORANGE_COLOR;
    [self addSubview:topView];
    
    UIView *topBackGround = [[UIView alloc]initWithFrame:topView.frame];
    topBackGround.backgroundColor = CT_HEADER_WHITE_COLOR;
    topBackGround.alpha = 0.98;
    [topView addSubview:topBackGround];
    //标题
    UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 20, CT_HEADER_SCREEN_WIDTH, 44)];
    titleLabel.text = [CTAppLanguage localizedStringForKey:@"aboutUsView_title_text" withValue:nil withTable:@"Language"];
    titleLabel.font = [UIFont systemFontOfSize:19.0f];
    titleLabel.textColor = CT_HEADER_GREEN_COLOR;
    titleLabel.textAlignment = NSTextAlignmentCenter;
    [topView addSubview:titleLabel];
    
    //返回按钮
    UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
    backButton.frame = CGRectMake(0, 20, 44, 44);
    [backButton addTarget:self action:@selector(backButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    [backButton setImage:[UIImage imageNamed:CT_HEADER_BACK_IMAGE] forState:UIControlStateNormal];
    [backButton setImage:[UIImage imageNamed:CT_HEADER_BACK_IMAGE_CLICK] forState:UIControlStateHighlighted];
    [topView addSubview:backButton];
    
    UILabel * topBottomLine = [[UILabel alloc]initWithFrame:CGRectMake(0, topView.height-0.5, CT_HEADER_SCREEN_WIDTH, 0.5)];
    topBottomLine.backgroundColor = CT_HEADER_DEEPLINE_COLOR;
    [topView addSubview:topBottomLine];
}

- (void)createAboutUsView
{
    UIImageView *iconImageView = [[UIImageView alloc]initWithFrame:CGRectMake((CT_HEADER_SCREEN_WIDTH-77)/2, topView.bottom+40, 77, 77)];
//    iconImageView.layer.masksToBounds = YES;
//    iconImageView.layer.cornerRadius  = 20;
    iconImageView.image = [UIImage imageNamed:@"about_logo"];
    [self addSubview:iconImageView];
    
    UILabel *appNameLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, iconImageView.bottom+15, CT_HEADER_SCREEN_WIDTH, 21)];
    appNameLabel.text = [CTAppLanguage localizedStringForKey:@"aboutUsView_appName_text" withValue:nil withTable:@"Language"];
    appNameLabel.textAlignment  = NSTextAlignmentCenter;
    appNameLabel.textColor = CTABOUTUSVIEW_APPNAME_COLOR;
    appNameLabel.font = [UIFont fontWithName:nil size:21];
    [self addSubview:appNameLabel];
    
    versionLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, appNameLabel.bottom+10, CT_HEADER_SCREEN_WIDTH, 21)];
//    versionLabel.text = [CTAppLanguage localizedStringForKey:@"aboutUsView_appName_text" withValue:nil withTable:@"Language"];
    versionLabel.textAlignment  = NSTextAlignmentCenter;
    versionLabel.textColor = CTABOUTUSVIEW_VERSION_COLOR;
    versionLabel.font = [UIFont fontWithName:nil size:15];
    [self addSubview:versionLabel];
    
    UILabel *topLineLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, versionLabel.bottom+20, CT_HEADER_SCREEN_WIDTH, 0.5)];
    topLineLabel.backgroundColor = CT_HEADER_BRIGHTLINE_COLOR;
    [self addSubview:topLineLabel];
    NSArray *headImageNameStr = [NSArray arrayWithObjects:@"yonghuxieyi",@"guanfangwangzhan", nil];
    NSArray *titlNameStr =[NSArray arrayWithObjects:[CTAppLanguage localizedStringForKey:@"aboutUsView_label_text2" withValue:nil withTable:@"Language"],[CTAppLanguage localizedStringForKey:@"aboutUsView_label_text3" withValue:nil withTable:@"Language"],[CTAppLanguage localizedStringForKey:@"aboutUsView_label_text4" withValue:nil withTable:@"Language"], nil];
    for (int i = 0; i < headImageNameStr.count; i++)
    {
        UIImageView *headImageView = [[UIImageView alloc]initWithFrame:CGRectMake(10, topLineLabel.bottom+13.5+i*45, 18, 18)];
        headImageView.image = [UIImage imageNamed:headImageNameStr[i]];
        [self addSubview:headImageView];
        
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(headImageView.right+10, topLineLabel.bottom+i*45, CT_HEADER_SCREEN_WIDTH-70, 45)];
//        if (i == 2)
//        {
//            NSString *str = [CTAppLanguage localizedStringForKey:@"aboutUsView_jonIn_text" withValue:nil withTable:@"Language"];
//            label.frame = CGRectMake(headImageView.right+10, topLineLabel.bottom+i*55, CT_HEADER_SCREEN_WIDTH-60-59, 55);
//            UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
//            button.frame = CGRectMake(label.right, label.origin.y+13, 59, 28);
//            [button addTarget:self action:@selector(joinBtnAction:) forControlEvents:UIControlEventTouchUpInside];
//            [button setTitle:str forState:UIControlStateNormal];
//            [button setTitle:str forState:UIControlStateHighlighted];
//            [button setTitleColor:SET_WORD_ORANGE_COLOR forState:UIControlStateNormal];
//            [button setTitleColor:SET_WORD_CLICK_ORANGE_COLOR forState:UIControlStateHighlighted];
//            [button setBackgroundImage:[UIImage imageNamed:@"about_icon_bg_join"] forState:UIControlStateNormal];
//            [button setBackgroundImage:[UIImage imageNamed:@"about_icon_bg_join_click"] forState:UIControlStateHighlighted];
//            [self addSubview:button];
//            
//        }
        label.text = titlNameStr[i];
        label.textColor = SET_LABEL_TEXT_COLOR;
        label.textAlignment = NSTextAlignmentLeft;
        label.font = [UIFont fontWithName:nil size:15];
        [self addSubview:label];
        
//        if (i != 3)
//        {
//            UIImageView *arrowsImageView = [[UIImageView alloc]initWithFrame:CGRectMake(label.right, topLineLabel.bottom+15 +i*45, 15, 15)];
//            arrowsImageView.image = [UIImage imageNamed:@"about_icon_go"];
//            [self addSubview:arrowsImageView];
//        }
        //label
        if (i==1)
        {
            UILabel *bottomLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, topLineLabel.bottom+45+i*45, CT_HEADER_SCREEN_WIDTH, 0.5)];
            bottomLabel.backgroundColor = CT_HEADER_BRIGHTLINE_COLOR;
            [self addSubview:bottomLabel];
        }
        else
        {
            UILabel *bottomLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, topLineLabel.bottom+45+i*45, CT_HEADER_SCREEN_WIDTH-20, 0.5)];
            bottomLabel.backgroundColor = CT_HEADER_BRIGHTLINE_COLOR;
            [self addSubview:bottomLabel];
        }
        
        
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        button.frame = CGRectMake(0, topLineLabel.bottom+i*45, label.width, 110);
        [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
        button.tag = 1001+i;
        [self addSubview:button];
    }
    
}
//加入按钮
- (void)joinBtnAction:(UIButton *) sender
{
    if ([self.delegate respondsToSelector:@selector(aboutUsViewJoinBtnAction:)])
    {
        [self.delegate aboutUsViewJoinBtnAction:self];
    }
}
//返回按钮
- (void)backButtonAction:(UIButton *) sender
{
    if ([self.delegate respondsToSelector:@selector(aboutUsViewBackBtnAction:)])
    {
        [self.delegate aboutUsViewBackBtnAction:self];
    }
}
//
- (void)buttonAction:(UIButton *)sender
{
    switch (sender.tag)
    {
        case CT_SETVIEW_BUTTON0:
            if ([self.delegate respondsToSelector:@selector(aboutUsViewVersionBtnAction:)])
            {
                [self.delegate aboutUsViewVersionBtnAction:self];
            }
            break;
        case CT_SETVIEW_BUTTON1:
            if ([self.delegate respondsToSelector:@selector(aboutUsViewaGreementBtnAction:)])
            {
                [self.delegate aboutUsViewaGreementBtnAction:self];
            }
            break;
        case CT_SETVIEW_BUTTON2:
            if ([self.delegate respondsToSelector:@selector(aboutUsViewOfficialBtnAction:)])
            {
                [self.delegate aboutUsViewOfficialBtnAction:self];
            }
            break;
//        case CT_SETVIEW_BUTTON3:
//            if ([self.delegate respondsToSelector:@selector(aboutUsViewOpinionBtnAction:)])
//            {
//                [self.delegate aboutUsViewOpinionBtnAction:self];
//            }
//            break;
        default:
            break;
    }
}
#pragma mark -setter-
- (void) setVersionsStr:(NSString *)versionStr
{
    versionLabel.text = versionStr;
}

@end
